package com.jye.rseven.user.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.jye.rseven.Constants.MyConstants;
import com.jye.rseven.domain.Advertise;
import com.jye.rseven.service.AdvertiseService;
import com.jye.rseven.domain.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/advertise")
@Api(tags = "广告控制器API")
public class AdvertiseController {

    @Reference
    AdvertiseService advertiseService;

    @GetMapping("/findAllAd")
    @ApiOperation(value = "查找所有广告", notes = "查找所有广告", httpMethod = "GET")
    public JsonResult findAllAd(){
        JsonResult jsonResult = new JsonResult();
        List<Advertise> advertiseList = advertiseService.findAllAd();
        if(advertiseList.size()!=0){
            jsonResult.setData(advertiseList);
        }else{
            jsonResult.setCode("500");
            jsonResult.setMsg("暂无广告");
        }
        return jsonResult;
    }

    @GetMapping("/findIndexAd")
    @ApiOperation(value = "查找首页广告", notes = "查找首页广告", httpMethod = "GET")
    public JsonResult findIndexAd(){
        JsonResult jsonResult = new JsonResult();
        String type = MyConstants.advertiseType.index;
        List<Advertise> advertiseList = advertiseService.findAdByType(type);
        if(advertiseList.size()!=0){
            jsonResult.setData(advertiseList);
        }else{
            jsonResult.setCode("500");
            jsonResult.setMsg("暂无广告");
        }
        return jsonResult;
    }

    @GetMapping("/findRecAd")
    @ApiOperation(value = "查找推荐广告", notes = "查找推荐广告", httpMethod = "GET")
    public JsonResult findRecAd(){
        JsonResult jsonResult = new JsonResult();
        String type = MyConstants.advertiseType.rec;
        List<Advertise> advertiseList = advertiseService.findAdByType(type);
        if(advertiseList.size()!=0){
            jsonResult.setData(advertiseList);
        }else{
            jsonResult.setCode("500");
            jsonResult.setMsg("暂无广告");
        }
        return jsonResult;
    }



}
